package ${package.ServiceImpl}

import com.baomidou.mybatisplus.core.toolkit.Wrappers
import ${superServiceImplClassPackage}
import com.common.util.CommonUtil.notEmpty
import ${package.Entity}.${entity}
import ${package.Mapper}.${table.mapperName}
import ${package.Service}.${table.serviceName}
import org.springframework.stereotype.Service
import java.io.Serializable
import javax.annotation.Resource

/**
 * <p>
 * ${table.comment!} 服务实现类
 * </p>
 *
 * @author ${author}
 */
@Service
<#if kotlin>
open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {
</#if>

    @Resource
    private lateinit var ${serviceNameSimple}Mapper: ${table.mapperName}

    override fun detail(id: Serializable): ${entity}? {
        val value = getById(id)
        return fill(value)
    }

    override fun getList(value: ${entity}): List<${entity}> {
        val query = Wrappers.query<${entity}>()
    <#list table.fields as field>
        if (notEmpty(value.${field.propertyName})) {
        <#if field.name == "create_time">
            query.between(${entity}.${field.name?upper_case}, value.createTime, value.updateTime)
        <#else>
            query.eq(${entity}.${field.name?upper_case}, value.${field.propertyName})
        </#if>
        }
    </#list>
        orderBy(value, query)
        val list = ${serviceNameSimple}Mapper.selectList(query)
        list.forEach { fill(it) }
        return list
    }

    override fun fill(value: ${entity}?): ${entity}? {
        if (value == null) {
            return null
        }

        return value
    }

}
